package com.yunmai11.yunmai;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.yunmai11.yunmai.activity.WaterActivity;
import com.yunmai11.yunmai.adapter.HomeAdapter;
import com.yunmai11.yunmai.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity implements HomeAdapter.OnItemClickListener {
    private RecyclerView main_rv;
    private HomeAdapter adapter;
    private List<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //getActionBar().setTitle("云卖驿站");

        data = new ArrayList<String>();
        data.add("水费");
        data.add("电费");
        data.add("燃气费");
        data.add("手机话费");
        data.add("有线电视");
        data.add("宽带费");

        initView();
    }

    private void initView()
    {
        main_rv = (RecyclerView) findViewById(R.id.main_rv);
        main_rv.setLayoutManager(new GridLayoutManager(this, 2));
        adapter = new HomeAdapter(this, data);
        adapter.setOnItemClickListener(this);
        main_rv.setAdapter(adapter);

    }

    @Override
    public void onItemClick(View view, int position) {
        Toast.makeText(this, data.get(position), Toast.LENGTH_LONG).show();
        switch (position) {
            case 0:
                Intent waterIntent = new Intent(this, WaterActivity.class);
                startActivity(waterIntent);
                break;
        }
    }

    @Override
    public void onItemLongClick(View view, int position) {
        CommonUtils.showToast(this, "long click->"+position);
    }
}
